#pragma once
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <unordered_map>
#include <string>
class CSubscriber;
class CPublisher;
namespace DDS_PARAMETER {
	struct DDS_Attribute;
	enum ReturnCode;
	enum Reliability;
	enum PublishMode;
	enum HistoryKind;
	enum Durability;
};
class CParticipantCtrl 
{
public:
	CParticipantCtrl();
	~CParticipantCtrl();
	DDS_PARAMETER::ReturnCode init_by_xml_profile(const DDS_PARAMETER::DDS_Attribute& dds_attr,
		std::string xml_path, uint32_t domain_id, std::string participant_profile,
		std::string topic_profile, std::string type_name, std::string rw_profile,
		std::string topic_name, bool is_writer);

	DDS_PARAMETER::ReturnCode init_all_by_default_qos(unsigned int domain_id, std::string type_name,
		std::string participant_name, std::string topic_name, uint32_t call_back_ref, bool is_writer);

	DDS_PARAMETER::ReturnCode init(const DDS_PARAMETER::DDS_Attribute& dds_attr, bool is_writer);
	DDS_PARAMETER::ReturnCode publish(std::string topic_name, const uint32_t& index, 
		const uint64_t& timestamp, const std::string& msg);

	bool has_matched(const std::string& topic_name, bool is_writer);

	void remove_publisher(std::string topic_name);
	void remove_subscriber(std::string topic_name);
	void remove_topic(std::string topic_name);
private:
	DDS_PARAMETER::ReturnCode create_participant(std::string xml_path, uint32_t domain_id, std::string participant_profile);
	DDS_PARAMETER::ReturnCode create_participant(const DDS_PARAMETER::DDS_Attribute& dds_attr);
	DDS_PARAMETER::ReturnCode create_participant(uint32_t domain_id, std::string participant_name);
	eprosima::fastdds::dds::Topic* create_topic(std::string topic_name, std::string type_name, std::string profile);
	eprosima::fastdds::dds::Topic* create_topic(std::string topic_name, std::string type_name);
	DDS_PARAMETER::ReturnCode create_publisher(eprosima::fastdds::dds::Topic* topic, std::string profile);
	DDS_PARAMETER::ReturnCode create_publisher(eprosima::fastdds::dds::Topic* topic, const DDS_PARAMETER::DDS_Attribute& dds_attr);
	DDS_PARAMETER::ReturnCode create_publisher(eprosima::fastdds::dds::Topic* topic);
	DDS_PARAMETER::ReturnCode create_subscriber(eprosima::fastdds::dds::Topic* topic, std::string profile, uint32_t call_back_ref);
	DDS_PARAMETER::ReturnCode create_subscriber(eprosima::fastdds::dds::Topic* topic, const DDS_PARAMETER::DDS_Attribute& dds_attr);
	DDS_PARAMETER::ReturnCode create_subscriber(eprosima::fastdds::dds::Topic* topic, uint32_t call_back_refs);
	bool register_type();
private:
	eprosima::fastdds::dds::DomainParticipant* m_participant_;
	eprosima::fastdds::dds::TypeSupport m_type_;
	std::unordered_map<std::string, eprosima::fastdds::dds::Topic*> m_topics_;
	std::unordered_map<std::string, std::unique_ptr<CSubscriber>> m_susbcribers_;
	std::unordered_map<std::string, std::unique_ptr<CPublisher>> m_publishers_;
};